import bp
import struct

if __name__ == '__main__':
    nn = bp.BPNeuralNetwork()
    with open("/sdcard/Git/pybp/mnist/train-labels-idx1-ubyte","rb") as trlf :
      trlb = trlf.read()
    mn,co = struct.unpack("!2I",trlb[0:8])
    print(mn,co)
    labels = []
    for i in range(1,co+1) :
      la = struct.unpack("!B",trlb[7+i:8+i])
      labels.append(la[0])
    print(labels[0])
    cases = [
      [0, 0, 0, 0],
      [0, 1, 1, 0],
      [1, 1, 0, 0],
      [0, 0, 1, 1],
    ]
    labels = [[0,0], [1,1], [1,0], [0,1]]
    nn.setup(4, 7, 2)
    nn.train(cases, labels, 10000, 0.05, 0.1)
    for case in cases:
      print(nn.predict(case))
